package com.example.firstopenglproject

import android.content.Context
import android.opengl.GLES30.GL_COLOR_BUFFER_BIT
import android.opengl.GLES30.glClear
import android.opengl.GLES30.glViewport
import android.opengl.GLES30.glClearColor
import android.opengl.GLSurfaceView
import android.opengl.GLSurfaceView.Renderer
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class FirstOpenGLProjectView(context: Context) : GLSurfaceView(context){

    init {
        setEGLContextClientVersion(3)
        setRenderer(FirstOpenGLProjectRenderer())
    }

    private inner class FirstOpenGLProjectRenderer : Renderer {
        override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
            // Set the background clear color to red. The first component is
            // red, the second is green, the third is blue, and the last
            // component is alpha, which we don't use in this lesson.
            glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        }

        override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
            // Set the OpenGL viewport to fill the entire surface.
            glViewport(0, 0, width, height);
        }

        override fun onDrawFrame(gl: GL10?) {
            // Clear the rendering surface.
            glClear(GL_COLOR_BUFFER_BIT);
        }

    }

}